<?php
/**
 * 单表数据库
 */
class Data_One
{
    private $dbproxy;

    public function __construct()
    {
        $this->dbproxy = new Data_DB();
    }

    function insert($kind, $insertField, $updateField = array(), $changeField = array(), $notEscFields=array())
    {
        $sql = Tool_Sql::insert($kind, $insertField, $updateField, $changeField, $notEscFields);
        return $this->dbproxy->sQuery($kind, 1, $sql);
    }

	function insertBulk($kind, $insertField, $notEscFields = array())
	{
		$sql = Tool_Sql::insertBulk($kind, $insertField, $notEscFields);
		return $this->dbproxy->sQuery($kind, 1, $sql);
	}

    function delete($kind, $where)
    {
    	if (is_array($where))
    	{
	        $sql = Tool_Sql::delete($kind, $where);
	    }
	    else if (is_string($where))
	    {
	    	if(strlen($where) == 0)
        	{
        		assert(0);	//不允许删除所有
         		return false;
        	}
        	$sql = "delete from ".$kind." where ".$where;
	    }
	    else
	    {
	    	assert(0);
	    }
        return $this->dbproxy->sQuery($kind, 1 ,$sql);
    }

    function update($kind, $updateField, $changeField = array(), $where, $notEscFields=array())
    {
       	$sql = Tool_Sql::update($kind, $updateField, $changeField, $where, $notEscFields);
        if(0 == strlen($sql))
        {
            return false;
        }
        return $this->dbproxy->sQuery($kind, 1 ,$sql);
    }

    function select($kind, $selectField, $whereField=array(), $order="", $start=0, $num=0, $cacheTime=0)
    {
        $sql = Tool_Sql::select($kind, $selectField, $whereField, $order, $start, $num);
        return $this->dbproxy->sQuery($kind, 1 ,$sql, $cacheTime);
    }
}

?>